version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE A.IV OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

/* PRELIMINARIES */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed_Heterog.dta", clear
#d					;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
#d					cr

/* DEFINE TREATMENT VARIABLE */

g					logtaxpaid=log(TaxPaid)
bys				regno:egen namefreq=min(name_count_v2)
drop				if year>=2012
g					after=year>=2010
g					treat=(namefreq<=40)
g					treat_after=treat*after

/* 1. TAX OFFICE (LAHORE, KARACHI, ISLAMABAD VS. OTHERS)*/

cap				drop trait* treat_after_trait
g					trait=(it_office_id==1 | it_office_id==6 | 					///
					it_office_id==10 | it_office_id==16 | it_office_id==66 			///
					| it_office_id==70 | it_office_id==74 | it_office_id==97 		///
					| it_office_id==9 | it_office_id==20)
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
local				j=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait if it_office_id<., absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 2. PERSONAL CITY!=BUSINESS CITY */

cap				drop trait* treat_after_trait
g					trait=(personal_city_id!=business_city_id)		
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait if personal_city_id>0 & personal_city_id<. & business_city_id>0 & business_city_id<., absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 3. MORE THAN ONE BUSINESSES */

cap				drop trait* treat_after_trait
g					trait=(no_of_business>1)		
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait if no_of_business<., absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 4. GENDER */

cap				drop trait* treat_after_trait
g					trait=(gender=="F" | gender=="f" | gender=="2")		
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait if gender!="", absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 5. FILING DATE */

g 					double fdate=dofc(return_filing_date)
forvalues		y=2006/2011 {
xtile 			quart_`y'_t=fdate if year==`y', nq(4)
bys				regno:egen quart_`y'=min(quart_`y'_t)
drop 				quart_`y'_t
}
egen				quart=rowtotal(quart_*) 
cap				drop trait* treat_after_trait
qui				sum quart,d
g					trait=(quart<=r(p50))		
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait if fdate<., absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 6. AGE */

g 					double bdate=dofc(birth_foundation_date)
g 					byear=year(bdate)
g 					age=2016-byear								
cap				drop trait* treat_after_trait
qui				sum age,d
g					trait=(age<=r(p50))		
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait if bdate<., absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 7. BUNCHER */

matrix 			input bunch_se=   (100,2\110,2\125,3\150,5\175,3\200,5\300,5\400,10\500,15\600,5)	
g					buncher=0
forvalues 		n_notch=1(1)10 {
					local notch=bunch_se[`n_notch',1]*1000
					local lower=`notch' - (bunch_se[`n_notch',2]*1000)
					replace buncher=1 if taxableinc>`lower' & taxableinc<=`notch' & year<=2009
}
cap				drop trait* treat_after_trait
bys				regno:egen trait=max(buncher)
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait, absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 8. STRICTLY DOMINATED CHOICE */
	
matrix 			input dom=(100000,100503\110000,110556\125000,126276\150000,151546\175000,176823\200000,202105\300000,308108\400000,411111\500000,514286\	///
					   600000,617647)
g					dominated=0
forvalues 		n_notch=1(1)10 {
					local notch=dom[`n_notch',1]
					local dzd_u=dom[`n_notch',2]
					replace dominated=1 if taxableinc>`notch' & taxableinc<=`dzd_u' & year<=2009
}
cap				drop trait* treat_after_trait
bys				regno:egen trait=max(dominated)
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait, absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* 9. REVISED RETURN */
	
g					revised=section_code=="1205" & year<=2011 
cap				drop trait* treat_after_trait
bys				regno:egen trait=max(revised)
g					treat_after_trait=treat_after*trait
g					trait_after=trait*after
local				i=1
qui				areg logtaxpaid i.year treat_after trait_after treat_after_trait, absorb(regno) cluster(regno)
matrix			table[`i',`j']=_b[treat_after]
matrix			table[`i'+1,`j']=_se[treat_after]
matrix			table[`i'+2,`j']=_b[treat_after_trait]
matrix			table[`i'+3,`j']=_se[treat_after_trait]
matrix			table[`i'+4,`j']=e(N)
local				j=`j'+1

/* FORMATTING THE TABLE */ 

svmat 			table
keep				tab*
drop				table10-table18
keep				if _n<=5
g					c11=""
replace			c11="treat $\times$ after" in 1
replace			c11="treat $\times$ trait $\times$ after" in 3
replace			c11="Observations" in 5

forvalues 		c=1/9 {
g					c`c'=string(table`c',"%9.3f")
}
foreach			r in 2 4 {
forvalues		c=1/9 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/9 {
replace			c`c'=string(table`c',"%15.0fc") in 5
}
forvalues		s=1/15 {
g					s`s'="&"
}
g					l="\\"
foreach			r in 2 4 5 {
replace			l="\\\\" in `r'
}
order				c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 s8 c8 s9 c9 l
browse			c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 s8 c8 s9 c9 l


